#!/bin/bash

# 开发工具安装脚本
# 此脚本会安装常用的开发工具和编译器

echo "====================================="
echo "开始安装开发工具..."
echo "====================================="

# 更新包管理器
echo ""
echo "[1/6] 更新 apt 包管理器..."
sudo apt update

# 安装 C/C++ 开发工具
echo ""
echo "[2/6] 安装 build-essential (gcc, g++, make)..."
sudo apt install -y build-essential

# 安装 Python pip
echo ""
echo "[3/6] 安装 python3-pip..."
sudo apt install -y python3-pip

# 安装 CMake
echo ""
echo "[4/6] 安装 CMake..."
sudo apt install -y cmake

# 安装 Go 语言
echo ""
echo "[5/6] 安装 Go 语言..."
sudo apt install -y golang-go

# 安装 Rust (使用官方安装脚本)
echo ""
echo "[6/6] 安装 Rust 语言..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

# 加载 Rust 环境变量
source "$HOME/.cargo/env" 2>/dev/null || true

echo ""
echo "====================================="
echo "安装完成！正在验证安装..."
echo "====================================="

# 验证安装
echo ""
echo "已安装的工具版本："
echo "-----------------------------------"
echo -n "GCC: "
gcc --version | head -n1
echo -n "G++: "
g++ --version | head -n1
echo -n "Make: "
make --version | head -n1
echo -n "Python: "
python3 --version
echo -n "pip: "
pip3 --version | head -n1
echo -n "CMake: "
cmake --version | head -n1
echo -n "Go: "
go version
echo -n "Rust: "
rustc --version 2>/dev/null || echo "Rust 安装成功，请运行 'source ~/.cargo/env' 激活"
echo -n "Cargo: "
cargo --version 2>/dev/null || echo "请运行 'source ~/.cargo/env' 激活"
echo ""
echo "====================================="
echo "所有工具安装完成！"
echo "====================================="
echo ""
echo "注意：如果要使用 Rust，请运行："
echo "  source ~/.cargo/env"
echo "或重新打开终端。"
